#
# /*
#  *  Copyright 2021
#  *
#  *  This program is free software: you can redistribute it and/or modify
#  *  it under the terms of the GNU General Public License as published by
#  *  the Free Software Foundation, either version 3 of the License, or
#  *  (at your option) any later version.
#  *
#  *  This program is distributed in the hope that it will be useful,
#  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  *  GNU General Public License for more details.
#  *
#  *  You should have received a copy of the GNU General Public License
#  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#  *
#  * SPDX-License-Identifier: GPL-3.0+
#  * License-Filename: LICENSE
#  *
#  */
#
# clng llvm control flow graph:
# clang -emit-llvm hello.c -c -o main.bc
# opt -dot-cfg-only main.bc

bin_PROGRAMS=ilona yadot

ilona_SOURCES = \
	dp.c \
	dot.tab.c \
	lex.yy.c \
	splay-tree.c \
	dpus.c \
	dpun.c \
	dpcolor.c \
	dpmisc.c \
	dpn.c \
	dpe.c \
	dpg.c \
	dphl.c \
	lex.hl.c \
	dphlparser.c \
	dpmem.c


#
ilona_CFLAGS = \
	@CFLAGS@ @PACKAGE_CFLAGS@ @WARNING_CFLAGS@

#
ilona_tolink = -lz

# the -DCLIB is used in dp_mem.c to use glibc malloc/free and not gtk lib routines

# make only the c version with make ilonac
ilonac$(EXEEXT): $(ilona_SOURCES)
	make clean
	$(CC) $(ilona_CFLAGS) $(ilona_SOURCES) main.c -DCLIB -I. -I.. $(ilona_tolink) -lm -o ilona
	$(CC) --version

#
ilona$(EXEEXT): $(ilona_SOURCES)
	make clean
	$(CXX) $(ilona_CFLAGS) $(ilona_SOURCES) main.c -DCLIB -I. -I.. $(ilona_tolink) -lm -o ilona
	$(CXX) --version
	make clean
	$(CC) $(ilona_CFLAGS) $(ilona_SOURCES) main.c -DCLIB -I. -I.. $(ilona_tolink) -lm -o ilona
	$(CC) --version
	flex --version
	bison --version

#
indent:
	./lindent.sh $(ilona_SOURCES) main.h dp.h splay-tree.h lex.yy.h dpus.h dpmem.h yadot.c

# clang -emit-llvm hello.c -c -o main.bc
# opt -dot-cfg-only main.bc
bc:
	clang -emit-llvm -c -I. -I.. dp.c -o dp.bc
	opt-7 -dot-cfg-only dp.bc
	gcc -c -I. -I.. -fdump-rtl-all-graph dp.c

#	opt-7 -dot-cfg dp.bc

yadot:
	$(CC) $(ilona_CFLAGS) $(ilona_SOURCES) yadot.c sfg.c -DCLIB -I. -I.. $(ilona_tolink) -lm -o yadot
	./yadot test.dot


#
clean-generic:
	rm -v -f *.bc
	rm -v -f ./massif.out.*
	rm -v -f ./a.out
	rm -v -f *~
	rm -v -f ./*.so.1
	rm -v -f ./*.o
	rm -v -f ./*.a
	rm -v -f ./*.i
	rm -v -f ./*.s
	rm -v -f ./O
	rm -v -f ./OO
	rm -v -f ./O1
	rm -v -f ./O2
	rm -v -f ./O3
	rm -v -f ./dsmake.output
	rm -v -f ./dsmake.warnings
	rm -v -f ./dsmake.errors
	rm -v -f *.*r.*
	rm -v -f *.*t.*
	rm -v -f *.plist
	rm -v -f *.ps
	rm -v -f ./lemon
	rm -v -f ./yadot

# /* end */
